//
//  NoNameViewController.m
//  Second
//
//  Created by Martin.P on 16/7/14.
//  Copyright © 2016年 蓝鸥科技有限公司西安分公司. All rights reserved.
//

#import "NoNameViewController.h"

@interface NoNameViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableview;
//接受内容的数组
@property (nonatomic,strong)NSMutableArray *dataSource;

@end

@implementation NoNameViewController
- (NSMutableArray *)dataSource{
    if (!_dataSource) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableview registerNib:[UINib nibWithNibName:@"NoNameCell" bundle:nil] forCellReuseIdentifier:@"no_name"];
    self.tableview.rowHeight = 200.0f;
    
    [RequestManager fecthDataWithUrl:NoNameUrl parameter:@{} mehtod:@"GET" compelet:^(NSData *data) {
        NSDictionary *bigDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        
        for (NSDictionary *smallDic in bigDic[@"topics"]) {
            NSLog(@"%@",smallDic);
            NoNameModel *model = [[NoNameModel alloc]init];
            [model setValuesForKeysWithDictionary:smallDic];
            [self.dataSource addObject:model];
            
            
        }
    } updateUI:^{
        [self.tableview reloadData];
        
    }];
//    [self fetchData];
    
//    self.automaticallyAdjustsScrollViewInsets = YES;
}
//push到下一级
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    
    
}
- (void)fetchData{
    [RequestManager fecthDataWithUrl:NoNameUrl parameter:@{} mehtod:@"GET" compelet:^(NSData *data) {
        NSDictionary *bigDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        
        for (NSDictionary *smallDic in bigDic[@"topics"]) {
            NSLog(@"%@",smallDic);
            NoNameModel *model = [[NoNameModel alloc]init];
            [model setValuesForKeysWithDictionary:smallDic];
            [self.dataSource addObject:model];
           
            
        }
    } updateUI:^{
        [self.tableview reloadData];
        
    }];
    
    
}
//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    return 1;
//}
#pragma mark ----tableviewDelegate---
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NoNameCell *cell = [tableView dequeueReusableCellWithIdentifier:@"no_name" forIndexPath:indexPath];
    //NoNameModel *medel = self.dataSource[indexPath.row];
    [cell setCellWithNoNameModel:self.dataSource[indexPath.row]];
    //cell.textLabel.text = medel.title;
    
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
